/*
 * SipServer.h
 *
 *  Created on: Dec 10, 2011
 *      Author: shaohong
 */

#ifndef SIPSERVER_H_
#define SIPSERVER_H_

#include <map>

#include "SipMessage.h"
#include "SipDialog.h"
#include "RadioStreamer.h"
#include <pthread.h>
#include <vector>

using namespace std;

namespace nmps {


struct SipServerThreadParams {
    SipServer * sipServer;
};

class SipServer {
public:
	SipServer();
	virtual ~SipServer();

	// handle the incoming SipMsg
	void handleSipMessage(char * receiveMsg);

	// find the SipDialog associated with the given callid;
	SipDialog * findSipDialog(string callid);

	// remove the SipDialog associated with the given callid;
	void removeDialog(string callid);


	//returns the contact Address of the SIP server
	static string getContactAddress();

	//get the IP address of local interface;
	static string getLocalInterfaceIP();

	void sendSipMessage(SipMessage * sipMsg);

	int serverSocketFD;

	//add radio streaming, of channelNo, to client with the given RTP IP and Port
	void addRadioStreaming(unsigned int channelNo, string clientIP, int clientPort);

	//remove the given client from radio streaming of channelNo
	void removeRadioStreaming(int channelNo, string clientIP, int clientPort);

	int getNumberOfRadioStations();

	void addRadioStreamer(RadioStreamer * radioStreamer);

	//start the SipServer service
	void startService();

	pthread_t getSipServerThread();

	bool isValidChannelNumber(unsigned int channelNumber);

private:
	// map of Sip Dialogs where call-id is the key and value is the sipDialog
	map<string, SipDialog *> sipDialogMap;

	static string contactAddress;

	vector<RadioStreamer *> radioStreamerList;

	pthread_t sipServerThread;
};

} // end of namespace


#endif /* SIPSERVER_H_ */
